<template>
	<web-view v-if="isInit" :src="url" @message="messageHandler"></web-view>
</template>

<script>
	import {
		startUrlFh
	} from '../../utils/lib'

	export default {
		data() {
			return {
				url: '',
				isInit: false
			}
		},
		onLoad(res) {
			this.initData(res)
		},
		methods: {
			async initData(res) {
				const urlTemp = decodeURIComponent(res.url)
				this.url = `${urlTemp}${startUrlFh(urlTemp)}isWxMini=1`
				const isGetLocal = res.isGetLocal
				if (isGetLocal) {
					await new Promise((resolve) => {
						uni.getLocation({
							type: 'wgs84',
							success: (res) => {
								this.url =
									`${this.url}${startUrlFh(this.url)}longitude=${res.longitude}&latitude=${res.latitude}`
								resolve()
							},
							fail: function(res) {
								console.log('当前位置失败：', res);
								resolve()
							}
						});
					})
				}
				this.isInit = true
			},
			errorHandler(err) {
				console.error(err)
			},
			messageHandler(msg) {
				console.log('messageHandler', msg)

			}
		},
	}
</script>

<style>

</style>